may 2014 docid024055 rev 2 1/51 AN4221 application note i2c protocol used in the stm32 bootloader introduction this application note describes the i2c prot ocol used in the stm32 microcontroller bootloader. it details each supported command. for more information about the i2c hardware resources and requirements for your device bootloader, please refer to application note an2606 ?stm32 microcontroller system memory boot mode?. . table 1. applicable products type part number or product series microcontrollers stm32f0 series: ? stm32f042xx, stm32f072xx stm32f3 series: ? stm32f318xx, stm32f328xx ? stm32f334xx ? stm32f358xx, stm32f378xx ? stm32f303x4(6/8) stm32f4 series: ? stm32f401xx, stm32f411xx ? stm32f405xx, stm32f407xx ? stm32f415xx, stm32f417xx ? stm32f429xx, stm32f439xx www.st.com
contents AN4221 2/51 docid024055 rev 2 contents 1 i2c bootloader code sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2 bootloader command set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.1 get command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.2 get version command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 2.3 get id command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.4 read memory command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.5 go command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 2.6 write memory command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.7 erase memory command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.8 write protect command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 2.9 write unprotect command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 2.10 readout protect command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 2.11 readout unprotect command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 2.12 no-stretch write memory command . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 2.13 no-stretch erase memory command . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 2.14 no-stretch write protect command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 2.15 no-stretch write unprotect command . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 2.16 no-stretch readout protect command . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 2.17 no-stretch readout unprotect command . . . . . . . . . . . . . . . . . . . . . . . . . 46 3 bootloader protocol version evolution . . . . . . . . . . . . . . . . . . . . . . . . . 49 4 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
docid024055 rev 2 3/51 AN4221 list of tables 3 list of tables table 1. applicable products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 table 2. i2c bootloader commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 table 3. bootloader protocol versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 table 4. document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
list of figures AN4221 4/51 docid024055 rev 2 list of figures figure 1. bootloader for stm32 with i2c. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 figure 2. get command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 figure 3. get command: device si de . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 figure 4. get version: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 figure 5. get version: device side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 figure 6. get id command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 figure 7. get id command: device side. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 figure 8. read memory command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 figure 9. read memory command: device side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 figure 10. go command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 figure 11. go command: device side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 figure 12. write memory command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1 figure 13. write memory command: device side. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 figure 14. erase memory command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 figure 15. erase memory command: device si de . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 figure 16. write protect command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 figure 17. write protect command: device side. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 figure 18. write unprotect command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 figure 19. write unprotect command: device side. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 0 figure 20. readout protect command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1 figure 21. readout protect command: device side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 figure 22. readout unprotect command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 figure 23. readout unprotect command: device side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 figure 24. no-stretch write memory command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 figure 25. no-stretch write memory command: device side. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 figure 26. no-stretch erase memory command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 figure 27. no-stretch erase memory command: device side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 figure 28. no-stretch write protect command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 figure 29. no-stretch write protect command: device side. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 figure 30. no-stretch write unprotect command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 figure 31. no-stretch write unprotect command: device side. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 figure 32. nostretch readout protect command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 figure 33. no-stretch readout protect command: device side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 figure 34. no-stretch readout unprotect command: host side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 figure 35. no-stretch readout unprotect command: device side . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
docid024055 rev 2 5/51 AN4221 i2c bootloader code sequence 50 1 i2c bootloader code sequence figure 1. bootloader for stm32 with i2c note: the i2c slave address for each product's bootloader is specified in the an2606. once the system memory boot mode has been entered, and the stm32 microcontroller has been configured (for more details, refer to your stm32 system memory boot mode application note), the bootloader code begins to scan the i2c_sda line pin, waiting to detect its own address on the bus. once detected, the i2c bootloader firmware begins receiving host commands. 0 6 y 9 $ g g u h v v g h w h f w h g 6 o d y h d g g u h v v : d l w i r u d f r p p d q g * h w f p g u r x w l q h * h w f p g 5 ' f p g u r x w l q h * 2 f p g u r x w l q h - 3 w r b d g g u h v v & |